package com.thd.springboottest;


import com.thd.springboottest.springbootextends.customapplicationcontextinitializer.MyApplicationContextInitalizer;
import com.thd.springboottest.springbootextends.custombeandefinitionregistrypostprocessor.ExampleBeanA;
import com.thd.springboottest.springbootextends.custombeanpostprocessor.ExampleBeanB;
import com.thd.springboottest.springbootextends.custombeanpostprocessor.ExampleBeanC;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.stream.Stream;

@SpringBootApplication(scanBasePackages = "com.thd.springboottest")

public class Application {

//    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
//        return builder.sources(this.getClass());
//    }



    public static void main(String[] args) {
        //System.setProperty("spring.devtools.restart.enabled", "false");
        SpringApplication springApplication = new SpringApplication(Application.class);

        springApplication.addInitializers(new MyApplicationContextInitalizer());
        ConfigurableApplicationContext ctx = springApplication.run(args);

        ExampleBeanA bean = (ExampleBeanA)ctx.getBean(ExampleBeanA.class);
        System.out.println(bean);
        String[] exampleBeanANameInIoc = ctx.getBeanNamesForType(ExampleBeanA.class);
        Stream.of(exampleBeanANameInIoc).forEach(System.out::println);

//        ExampleBeanB exampleBeanB = ctx.getBean(ExampleBeanB.class);
//        System.out.println(exampleBeanB.getName());

        ExampleBeanC exampleBeanC = ctx.getBean(ExampleBeanC.class);
        System.out.println(exampleBeanC.getName());

        ExampleBeanC exampleBeanC1 = (ExampleBeanC)ctx.getBean("exampleBeanB");
        System.out.println(exampleBeanC1.getName());








        String[] names = ctx.getBeanDefinitionNames();
        System.out.println("========Regist Beans:======");
        Stream.of(names).forEach(System.out::println);
        System.out.println("===========================");

    }


}
